#include "EEExpMain.h"
#include <maya/MStatus.h>
#include <maya/MObject.h>
#include <maya/MFnPlugin.h>

#include <iostream>

#ifdef WIN32
	#pragma comment(lib,"Foundation.lib")
	#pragma comment(lib,"OpenMaya.lib")
	#pragma comment(lib,"OpenMayaFx.lib")
	#pragma comment(lib,"Image.lib")
	#pragma comment(lib,"OpenMayaAnim.lib")
#endif

#ifdef WIN32
	#define MLL_EXPORT extern __declspec(dllexport) 
#else
	#define MLL_EXPORT
#endif

char* g_OptionScript = "MayaFileExportScript";
char* g_DefaultOptions = "-namesonly=0;";

const bool WRITE_ASCII = false;

const char* EE_MODEL_EXPORTER_NAME = "ExodusEngine Model Exporter";
const char* EE_PLACE_EXPORTER_NAME = "ExodusEngine Placement Exporter";
const char* EE_WORLD_EXPORTER_NAME = "ExodusEngine World Exporter";

MLL_EXPORT MStatus initializePlugin( MObject obj )
{
	MStatus status;

	std::cout << "ExodusEngine Export Plugin - Data exporter for the ExodusEngine version 1.0" << std::endl;
	MFnPlugin plugin( obj, "Dacre Denny", "1.1", "Any");

	status =  plugin.registerFileTranslator( 
		EE_WORLD_EXPORTER_NAME, "none",
		EEWorldExporter::creator,
		(char*)g_OptionScript,
		(char*)g_DefaultOptions ); 

	if (status != MS::kSuccess)
		status.perror("[ERROR] Could not initalize world exporter");

	status =  plugin.registerFileTranslator( 
		EE_MODEL_EXPORTER_NAME, "none",
		EEModelExporter::creator,
		(char*)g_OptionScript,
		(char*)g_DefaultOptions ); 

	status =  plugin.registerFileTranslator( 
		EE_PLACE_EXPORTER_NAME, "none",
		EEPropExporter::creator,
		(char*)g_OptionScript,
		(char*)g_DefaultOptions ); 

	if (status != MS::kSuccess) 
		status.perror("[ERROR] Could not initalize model exporter");

	return status;
                                     
}

MLL_EXPORT MStatus uninitializePlugin( MObject obj )
{
	MFnPlugin plugin( obj );
	MStatus status;

	if (plugin.deregisterFileTranslator( EE_MODEL_EXPORTER_NAME ) != MS::kSuccess) 
		status.perror("[ERROR] Could not release model exporter");

	if (plugin.deregisterFileTranslator( EE_WORLD_EXPORTER_NAME ) != MS::kSuccess) 
		status.perror("[ERROR] Could not release world exporter");

	return status;
}